/******************************************************************************
 *
 * Project:		mGameEngine
 * File:		hdr.frag
 * Author:		karooolek
 * Created on:	2009-09-20
 *
 ******************************************************************************/

STRINGIZE(

uniform sampler2D texture;
uniform float strength;
uniform vec2 pixSize;

void main()
{
	// get color
	vec4 tex = texture2D(texture, vec2(gl_TexCoord[0]));
	
	// get neighbour pixels
	vec4 glow = vec4(0.0);
	
	if(strength > 0.0)
	{
		float dx = pixSize.x;
		float dy = pixSize.y;
		for(int i = 1; i <= 10; ++i)
		{
			vec4 p1 = texture2D(texture, vec2(gl_TexCoord[0]) - vec2(2*i * dx, 0));
			glow += p1 * p1;
			
			vec4 p2 = texture2D(texture, vec2(gl_TexCoord[0]) + vec2(2*i * dx, 0));
			glow += p2 * p2;
			
			vec4 p3 = texture2D(texture, vec2(gl_TexCoord[0]) - vec2(0, 2*i * dy));
			glow += p3 * p3;
			
			vec4 p4 = texture2D(texture, vec2(gl_TexCoord[0]) + vec2(0, 2*i * dy));
			glow += p4 * p4;
		}
		glow *= 0.025;
	}
	
	// mix with emerged bright colors
	gl_FragColor = tex + glow * strength;
	
	// clamp color
	gl_FragColor = clamp(gl_FragColor, 0.0, 1.0);
}

) // STRINGIZE
